<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <main id="app">
        <p>父组件累加结果：{{countAll}}</p>
        <sub-component @increase="handleIncrease"></sub-component>
        <sub-component @increase="handleIncrease"></sub-component>
    </main>
</body>
<script src="../vue.js"></script>
<script>
    Vue.component("sub-component",{
        // 组件模板：只有一个根节点
        template: `
            <div>
                <p>当前值：{{count}}</p>
                <button @click="increase">增加</button>
            </div>
        `,
        data() {
            return {
                count: 0
            }
        },
        methods: {
            increase() {
                this.count ++;
                this.$emit("increase");
            }
        }
    })

    new Vue({
        el: "#app",
        data() {
            return {
                countAll: 0
            }
        },
        methods: {
            handleIncrease() {
                this.countAll ++;
            }
        }
    })
</script>
</html>